﻿/*-------------------------------------------------------------------------------------
 * Project Name             : Gems
 * Created By               : Nanthini
 * Created Date             : 26 Oct 2012
 * Page Function            : Send the Password to User through Mail
 * -------------------------------------------------------------------------------------
 * Ref No           Name            Date            Reason
 * R-001            Nanthini        27 Oct 2012     Method Rearrange 
 * -------------------------------------------------------------------------------------
 */

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Security.Cryptography;

public partial class vp_Billing_Default : System.Web.UI.Page
{
    Encrypt encryptobj = new Encrypt();

    #region Page Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Clear();
        }
    }
    #endregion

    #region Button Events
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        this.SendMail();
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        this.Clear();
    }
    #endregion

    #region UserMethods

    /// 
    /// TODO:: R-001
    /// 
    public void Clear()
    {
        try
        {
            txtUsername.Text = string.Empty;
            txtEmail.Text = string.Empty;
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }

    }

    public void SendMail()
    {
        try
        {
            Hashtable hstb1 = new Hashtable();
            hstb1.Add("@EmailID", txtEmail.Text.Trim());
            hstb1.Add("@UserName", txtUsername.Text.Trim());
            DataTable dt = DataAccessLayer.GetDataTable("GemsUser_FetchPassword_SP", hstb1);
            if (dt.Rows.Count > 0)
            {

                SendMail send = new SendMail();
                string name = dt.Rows[0]["UserName"].ToString();
                string login = dt.Rows[0]["EmailID"].ToString();
                string pass = dt.Rows[0]["Password"].ToString();
                string DecryptPass = encryptobj.Decrypt(pass);
                int SuccessStatus = send.SendRegisterMail(login, name, login, DecryptPass);

                if (SuccessStatus == 0)
                    JSAlert.Show("Email successfully sended");
                else
                    JSAlert.Show("Unable to Send the Mail to the given EmailID");
            }
            else
            {
                JSAlert.Show("Entered Incorrect Login Id.");
            }
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }
    #endregion
}